/*
* $Id: PointForm.java 250 2011-01-17 21:36:24Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2011 by Volokitin Alexey
* All rights reserved
*
*/
package apiary.ui.journal;

import apiary.Apiary;
import apiary.component.journal.Wizard;
import apiary.db.UserFieldsStore.UserFieldsRecord;
import apiary.settings.SettingStore;
import apiary.settings.SettingsRecord;
import apiary.settings.SettingsRecord.Field;

import java.util.Vector;
import javax.microedition.lcdui.*;

public class PointForm extends UserFieldForm
{
    public class PointValue
    {
        public String namePoint;
        public String notePoint;
        public Vector userFields;

        public PointValue() {
            namePoint = new String();
            notePoint = new String();
            userFields = new Vector();
        }
    }

    PointValue pointValue;

    public PointForm(String name, Integer id, Wizard wiz, boolean nextCommand){
        super(name, wiz, id, nextCommand);
        setUserTable(UserFieldsRecord.TABLE_POINTS);
        Apiary apiary = Apiary.getInstance();
        append(new TextField(apiary.getLocaleString("NamePoint"), "", 256, TextField.ANY));
        Field field = (Field) SettingStore.getInstance().getData(SettingsRecord.NOTE_POINT);
        if(field.getValue() == Boolean.TRUE)
            append(new TextField(apiary.getLocaleString("Note"), "", 256, TextField.ANY));
        appendUserFields();
        pointValue = new PointValue();
    }

    public void setPointValue(PointValue point) {
        int beginUser = 1;
        pointValue = point;
        TextField name = (TextField) get(0);
        name.setString(point.namePoint);
        Field field = (Field) SettingStore.getInstance().getData(SettingsRecord.NOTE_POINT);
        if(field.getValue() == Boolean.TRUE){
            TextField note = (TextField) get(1);
            note.setString(point.notePoint);
            beginUser++;
        }
        setUserFieldsValue(beginUser, point.userFields);
    }

    public Object GetDataForm() {
        int beginUser = 1;
        PointValue value = new PointValue();
        TextField name = (TextField) get(0);
        value.namePoint = name.getString();
        value.notePoint = pointValue.notePoint;
        Field field = (Field) SettingStore.getInstance().getData(SettingsRecord.NOTE_POINT);
        if(field.getValue() == Boolean.TRUE){
            TextField note = (TextField) get(1);
            value.notePoint = note.getString();
            beginUser++;
        }
        value.userFields = getUserFieldsValue(beginUser);
        return value;
    }

    protected void commandUser(Command command) {
    }
}
